package strategy;

import strategy.duck.AbstractDuck;
import strategy.duck.GreenHeadDuck;
import strategy.duck.RedHeadDuck;
import strategy.flybehavior.NoFlyBehavior;

/**
 * @author: zhouyang
 * @descrpition: 策略模式
 * 1.提取变化部分 抽象成接口实现
 * 2.可以在不同子类中设置不同的策略来适应同样的类 不同的方法
 * @time: 2019-04-28 18:48
 */
public class Main {
    public static void main(String[] args) {
        AbstractDuck greenHeadDuck = new GreenHeadDuck();
        AbstractDuck redHeadDuck = new RedHeadDuck();

        greenHeadDuck.display();
        greenHeadDuck.fly();
        greenHeadDuck.quack();

        redHeadDuck.display();
        redHeadDuck.fly();
        redHeadDuck.quack();

        redHeadDuck.setFlyBehavior(new NoFlyBehavior());
        redHeadDuck.display();
        redHeadDuck.fly();
        redHeadDuck.quack();
    }
}
